<html><head>
	<meta charset="utf-8">
	<title>Test for Local Storage</title>
	<script type="text/javascript" src="../library/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="../library/js/json2.js"></script>
	<script type="text/javascript" src="../library/js/localStorageDB.js" ></script>
	<script type="text/javascript">
		$(document).ready(function() {
		var searchspace = ["this.firstName","this.lastName","this.organization","this.home.street","this.home.locality","this.home.city","this.home.state","this.home.country","this.home.email","this.home.landlineNo","this.home.mobileNo","this.office.street","this.office.locality","this.office.city","this.office.state","this.office.country","this.office.email","this.office.landlineNo","this.office.mobileNo"];
		try{
			var ls_geekcafe = localStorageDB("geekcafe");
		}
		catch(err){/opt/
			alert("Something went wrong");
		}
		
		if(ls_geekcafe.isNew())
		{
			alert('Got Licked');	
			ls_geekcafe.createTable("businesspartners",
				[ 
				  "id",
				  "json"
				]);
		}
		


		$("#btnRead").live("click",function(){
			$("#output").html(JSON.stringify(ls_geekcafe.query("businesspartners",{ID:"1"})));
		});

		$("#btnWrite").live("click",function(){
				post_param = JSON.stringify({token:'aafddg',vaultID:'',mySearchString:'',action:'query'});
				$.ajax({
					
					/*type:"GET",
					dataType: "json",
					url: "http://localhost/WebContent/puppet_rest/work.php/partners",*/
					type: "POST",
					dataType:"json",
					contentType:"application/json;charset=utf-8",
					url:"https://contactsbp.cloudfoundry.com/resource",
					data: post_param,
					success: function(data)
					{
						alert(data[0]["id"]);
						prepare_json = data;
						ls_geekcafe.insert("businesspartners",{id:data[0]["id"],json:prepare_json});
						ls_geekcafe.commit();
						$("#output").html(prepare_json);
					}
				});

		});

		$("#btnQuery").live("click",function(searchstring){

			searchstring = "Bangalore";
			var output = JSON.stringify(ls_geekcafe.query("businesspartners",function(data){
				$.each(data.json,function(){
					if($.inArray(searchstring,JSON.stringify(eval(searchspace))))
					{
						$("#output").html(JSON.stringify(this));		
					}
			});
		}));
	});
});

</script>
</head>
<body>
	<button type="button" id="btnRead">Read</button>
	<button type="button" id="btnWrite">Write</button>
	<button type="button" id="btnDelete">Delete</button>
	<button type="button" id="btnQuery">Query</button>
	<div id="output"></div>
</body>
</html>